# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: 6543 <6543@obermui.de>
pkgname=synapse
pkgver=1.96.1
pkgrel=1
pkgdesc="Matrix reference homeserver"
url="https://github.com/matrix-org/synapse"
arch="all"
license="Apache-2.0"
depends="
	python3
	py3-asn1
	py3-asn1-modules
	py3-attrs
	py3-authlib
	py3-bcrypt
	py3-bleach
	py3-canonicaljson
	py3-daemonize
	py3-eliot
	py3-icu
	py3-idna
	py3-ijson
	py3-immutabledict
	py3-jinja2
	py3-jsonschema
	py3-jwt
	py3-lxml
	py3-matrix-common
	py3-msgpack
	py3-netaddr
	py3-openssl
	py3-phonenumbers
	py3-pillow
	py3-prometheus-client
	py3-psycopg2
	py3-pydantic
	py3-pymacaroons
	py3-pynacl
	py3-saml2
	py3-service_identity
	py3-setuptools
	py3-signedjson
	py3-sortedcontainers
	py3-treq
	py3-twisted
	py3-txacme
	py3-txredisapi
	py3-typing-extensions
	py3-yaml
	"
makedepends="
	py3-gpep517
	py3-installer
	py3-poetry-core
	py3-setuptools-rust
	"
checkdepends="
	$depends
	py3-hiredis
	py3-mock
	py3-parameterized
	py3-twisted-tests
	"
pkgusers="synapse"
pkggroups="synapse"
install="$pkgname.pre-install $pkgname.post-install"
subpackages="$pkgname-openrc $pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/matrix-org/synapse/archive/v$pkgver.tar.gz
	synapse.initd
	synapse.confd
	"
options="net !check" # need updates for new jsonschema

case "$CARCH" in
arm*|aarch64)
	# seem to fail on builder networking
	options="$options !check"
	;;
esac


# secfixes:
#   1.95.1-r0:
#     - CVE-2023-43796
#   1.94.0-r0:
#     - CVE-2023-45129
#   1.93.0-r0:
#     - CVE-2023-41335
#     - CVE-2023-42453
#   1.85.1-r0:
#     - CVE-2023-32683
#     - CVE-2023-32682
#   1.74.0-r0:
#     - CVE-2023-32323
#   1.69.0-r0:
#     - CVE-2022-39335
#   1.68.0-r0:
#     - CVE-2022-39374
#   1.61.1-r0:
#     - CVE-2022-31052
#   1.47.1-r0:
#     - CVE-2021-41281
#   1.41.1-r0:
#     - CVE-2021-39164
#     - CVE-2021-39163
#   1.33.2-r0:
#     - CVE-2021-29471
#   1.30.1-r0:
#     - CVE-2021-3449
#   1.24.0-r0:
#     - CVE-2020-26257
#   1.21.1-r0:
#     - CVE-2020-26891
#   1.20.0-r0:
#     - CVE-2020-26890

prepare() {
	default_prepare

	git init .
}

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	export PYTHONPATH="$(echo .testenv/lib/python3*/site-packages/):$PWD"
	(
		# shellcheck disable=1091
		. .testenv/bin/activate
		trial -j"${JOBS:-2}" tests
	)
}

package() {
	python3 -m installer -d "$pkgdir" .dist/*.whl

	install -d -g synapse -o synapse -m775 \
		"$pkgdir"/etc/synapse \
		"$pkgdir"/var/lib/synapse

	cp -a synapse/res "$pkgdir"/var/lib/synapse
	chown -R synapse:synapse "$pkgdir"/var/lib/synapse/res

	install -Dm755 "$srcdir"/synapse.initd "$pkgdir"/etc/init.d/synapse
	install -Dm644 "$srcdir"/synapse.confd "$pkgdir"/etc/conf.d/synapse
}

sha512sums="
87b47f1f46ed6a39e5327464353094fd223aab907b5c4868590eb1d027bde6664d7eeb7e4c40e34113e13bdd4077df59569b08a2eac4b4a5f8c86f038d478f7b  synapse-1.96.1.tar.gz
7ac08b676b246647ebfa50f46525ed81d4fa53e83ab11d984f1cedc79ffbbcf12234424215f44f7038b82b7523c1e2fcac306d8bdc9d64648c5d994017b51e55  synapse.initd
7c022f0e00c8ac363d6d2e003b6389fb06a3934f68390ebac156cb46bc1366585e6b6cda07b15176bc62a00f5bf21bfda153ff5418b07331257a7075102a6f83  synapse.confd
"
